/* const http=require('http')
const app=http.createServer();
app.on('request',(req,res)=>{
    res.setHeader("Content-type","text/html;charset=utf-8")
    res.end("<h1>欢迎</h1>")
})
app.listen(3001,()=>{
    console.log("server is running...");
}) */
const http = require('http');

const server = http.createServer((req, res) => {

  const path = req.url;

  if (path === '/') {
    res.writeHead(300, {"Content-type":"text/html;charset=utf-8"});
    res.end('<h1>欢迎信息</h1>');
  } else if (path === '/about') {
    res.writeHead(300, {"Content-type":"text/html;charset=utf-8" });
    res.end('<h1>关于页面的内容</h1>');
  } else if (path === '/contact') {
    res.writeHead(300, {"Content-type":"text/html;charset=utf-8"});
    res.end('<h1>联系页面的内容<h1>');
  } else {
    res.writeHead(404, {"Content-type":"text/html;charset=utf-8" });
    res.end('<h1>错误页面</h1>');
  }
});

server.listen(3001, () => {
  console.log('服务器已启动，监听端口 3000');
});